import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;
import javax.swing.Action;
import java.awt.Scrollbar;
import java.awt.event.ActionListener;
import javax.swing.JScrollPane;
import javax.swing.border.TitledBorder;
import javax.swing.JScrollBar;


public class MainUi {

	private JFrame frame;
	private final Action action = new SwingAction();
	private Integer numItens;
	private Integer posItem;
	private JScrollPane scrollPaneListaDeMaterial;
	private JPanel panelListaDeMaterial;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainUi window = new MainUi();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainUi() {
		posItem = 45;
		numItens = 1;
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 850, 700);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JButton btnAdicionar = new JButton("Adicionar");
		btnAdicionar.setBounds(358, 26, 89, 23);
		btnAdicionar.addActionListener(new BtnAdicionarActionListener());
		frame.getContentPane().setLayout(null);
		btnAdicionar.setAction(action);
		frame.getContentPane().add(btnAdicionar);
		
		
		
		panelListaDeMaterial = new JPanel();
		panelListaDeMaterial.setBorder(new TitledBorder(null, "lista de material", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panelListaDeMaterial.setBounds(20, 10, 740, 600);
		panelListaDeMaterial.setPreferredSize(new Dimension(740,5000));
	//	frame.getContentPane().add(panel2);
		
		scrollPaneListaDeMaterial = new JScrollPane(panelListaDeMaterial);
		panelListaDeMaterial.setLayout(null);
		scrollPaneListaDeMaterial.setBounds(50, 50, 750, 600);
		
		scrollPaneListaDeMaterial.setAutoscrolls(true);
		scrollPaneListaDeMaterial.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		frame.getContentPane().add(scrollPaneListaDeMaterial);
	}
	private class SwingAction extends AbstractAction {
		public SwingAction() {
			putValue(NAME, "Adicionar");
			putValue(SHORT_DESCRIPTION, "Some short description");
		}
		public void actionPerformed(ActionEvent e) {
			PanelMaterial pm = new PanelMaterial((posItem)+20);
			posItem += 100;
			panelListaDeMaterial.add(pm);
			frame.getContentPane().add(scrollPaneListaDeMaterial);
			frame.repaint();
		}
	}
	private class BtnAdicionarActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
		}
	}
}
